<%@page import="com.dao.SqlOfUser"%>
<%@page import="com.servlet.M2"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="hyl.core.db.MyDB"%>
<%@page import="hyl.core.MyFun"%>
<%@page import="com.servlet.My"%>
<%@page import="java.io.PrintWriter"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
PrintWriter shuchu = response.getWriter();
	
	String 用户姓名 = request.getParameter("ualias");
	String 用户手机号 = request.getParameter("uphone");
	int 职称 = MyFun.str2int(request.getParameter("roleid"));
	String 邮箱 = request.getParameter("eml");
	int 用户所属 = MyFun.str2int(request.getParameter("yhss"));
	int 角色 = MyFun.str2int(request.getParameter("tt"));
	if(用户所属==0){
		shuchu.print("error3");
		shuchu.flush();
		shuchu.close();
		return;
	}
	String sql = "select * from user where uphone = ?";
	Object[] param = {用户手机号};
	MyDB db = My.getDB1();
	List<Map<String,Object>> list = db.queryList(sql, param);
	if(list.size()>0){
		shuchu.print("error");
		shuchu.flush();
		shuchu.close();
		return;
	}
	if(角色==1){
		sql = "select * from org id=? and uid is not null";
		Object[] ppap = {用户所属};
		List<Map<String,Object>> list2 = db.queryList(sql, ppap);
		if(list2.size()>0){
	shuchu.print("error2");
	shuchu.flush();
	shuchu.close();
	return;
		}
	}
	
	MyDB cdb = My.getCommitDB1();
	sql = "insert into user(uname,ualias,uphone,umail,roleid,istate,ctime,upass,state)values(?,?,?,?,?,?,now(),'96e79218965eb72c92a549dd5a330112',1)";
	Object[] params = {SqlOfUser.get_随机账号(),用户姓名,用户手机号,邮箱,职称,职称};
	long id = cdb.executeUpdate(sql, params);
	
	sql = "insert into user_conf(id)values(?)";
	Object[] param2= {id};
	cdb.executeUpdate(sql, param2);
	
	sql = "insert into user_ext(id,i0)values(?,?)";
	Object[] param3 = {id,用户所属};
	cdb.executeUpdate(sql, param3);
	
	sql = "insert into org_user (oid,uid,itype)values(?,?,?)";
	int itype = 1;
	if(职称==M2.ROLE_校长)itype=2;
	if(职称==M2.ROLE_教师)itype=1;
	Object[] param4 = {用户所属,id,itype};
	cdb.executeUpdate(sql, param4);
	
	if(角色==1){
		sql = "update org set uid=? where id=?";
		Object[] param5 = {id,用户所属};
		cdb.executeUpdate(sql, param5);
	}
	
	cdb.commit();
	shuchu.print("success");
	shuchu.flush();
	shuchu.close();
%>